package com.poi.java.controller;

import com.poi.java.dao.TableDao;
import com.poi.java.util.*;
import com.poi.java.v.tID;
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.TextSelection;
import com.spire.doc.documents.TextWrappingStyle;
import com.spire.doc.fields.DocPicture;
import com.spire.doc.fields.TextRange;
import org.apache.tomcat.util.json.JSONParser;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


@RestController
@RequestMapping("/word")
public class WordController {

    @Resource
    private TableDao tableDao;

//    private final  Document    document = new Document("/home/tdbg/docm/市场比较法及成本逼近法模板.doc");


    @PostMapping("/createNewWord")
    public Object createNewWord(@RequestBody tID tid) {
        return getresult(tid, true);
    }

    @PostMapping("/count")
    public Object count(@RequestBody tID tid) {
        return getresult(tid, false);
    }

    private Object getresult(tID tid, Boolean flog) {
        HashMap<String, String> hashMap = null;
        try {
            Map<String, String> totalMap = new HashMap();
            DecimalFormat df4 = new DecimalFormat("######0.00");
            DecimalFormat df2 = new DecimalFormat("######0");
            DecimalFormat df5 = new DecimalFormat("######0.0000");
            DecimalFormat df = new DecimalFormat("######0.00");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");

            //加载Word文档
            Document document = null;
            if (flog) {
                document = new Document("/home/tdbg/docm/cbbj.doc");
//                document = new Document("D:\\projectsd\\java\\src\\main\\resources\\word\\cbbj.doc");
            }



            //使用新文本替换文档中的指定文本
//        int i = document.replace("#delegate_name}", "张三丰", false, true);
//        System.out.println(i);

            Map<String, Object> land_material = tableDao.land_material((int) tid.getItemDetails().get("mid"));
            if (land_material.get("llms_des") == null || land_material.get("llms_des").equals("")) {
                land_material.put("llms_des", null);
            }
            String fourth_to = land_material.get("fourth_to").toString();
            String replace = fourth_to.replace("。", "");
            String replace1 = replace.replace(".", "");
            land_material.put("fourth_to", replace1);
            toMap(totalMap, land_material, "");

//        Map<String, Object> landProject = tableDao.land_project((int)tid.getItemDetails().get("mid"));
            List<Map<String, Object>> landProject1 = tableDao.land_project((int) tid.getItemDetails().get("mid"));
            Map<String, Object> landProject = landProject1.get(0);
            String valueDate = landProject.get("value_date").toString().substring(0,4);
            toMap(totalMap, landProject, "");
            String guidance_document = tableDao.guidance_document(land_material.get("regin").toString());

//            toMap(totalMap, guidance_document, "");
            totalMap.put("#region#", land_material.get("regin").toString());
            //公示低价成功
            totalMap.put("#filename_ech#", guidance_document);

            if (landProject.get("gjs1") != null) {
                Map<String, Object> appraiser = tableDao.appraiser(Integer.parseInt(landProject.get("gjs1").toString()));
                if (appraiser == null) {
                    totalMap.put("#appraiser_number1#", "");
                } else {
                    totalMap.remove("#gjs1#");
                    totalMap.put("#gjs1#", appraiser.get("name").toString());
                    totalMap.put("#appraiser_number1#", appraiser.get("number").toString());
                }
            }
            if (landProject.get("gjs2") != null) {
                Map<String, Object> appraiser = tableDao.appraiser(Integer.parseInt(landProject.get("gjs2").toString()));
                if (appraiser == null) {
                    totalMap.put("#appraiser_number2#", "");
                } else {
                    totalMap.remove("#gjs2#");
                    totalMap.put("#gjs2#", appraiser.get("name").toString());
                    totalMap.put("#appraiser_number2#", appraiser.get("number").toString());
                }
            }

            HashMap<String, Object> others = tid.getItemDetails();
            HashMap<String, Object> resultClass = tid.getResultClass();
            toMap(totalMap, others, "");
            toMap(totalMap, resultClass, "");
       /* String cbcyjj_regex = others.get("cbcyjj_regex").toString();
        String cbgbtj_regex = others.get("cbgbtj_regex").toString();
        String cbghys_regex = others.get("cbghys_regex").toString();
        String cbhjzl_regex = others.get("cbhjzl_regex").toString();
        String cbjcss_regex = others.get("cbjcss_regex").toString();
        String cbjt_regex = others.get("cbjt_regex").toString();
        String zsplan_regex = others.get("zsplan_regex").toString();
        String zsterrain_regex = others.get("zsterrain_regex").toString();
        String zsal_regex = others.get("zsal_regex").toString();
        String zsmj_regex = others.get("zsmj_regex").toString();
        String zsshape_regex = others.get("zsshape_regex").toString();
        String zssrc_regex = others.get("zssrc_regex").toString();
        String zssr_regex = others.get("zssr_regex").toString();
        String zsrg_regex = others.get("zsrg_regex").toString();
        String zsrr_regex = others.get("zsrr_regex").toString();
        String zsicd_regex = others.get("zsicd_regex").toString();
        String zsnature_regex = others.get("zsnature_regex").toString();
        String zsinfra_regex = others.get("zsinfra_regex").toString();
        String zsfs_regex = others.get("zsfs_regex").toString();
        String zshighway_regex = others.get("zshighway_regex").toString();
        String zsra_regex = others.get("zsra_regex").toString();*/
            Double src_regex = Double.valueOf(others.get("src_regex").toString()) * 100;
            totalMap.put("#src_regex_t#", String.valueOf(src_regex));
            Double sr_regex = Double.valueOf(others.get("sr_regex").toString()) * 100;
            totalMap.put("#sr_regex_t#", String.valueOf(sr_regex));
            Double shape_regex = Double.valueOf(others.get("shape_regex").toString()) * 100;
            totalMap.put("#shape_regex_t#", String.valueOf(shape_regex));
            Double mj_regex = Double.valueOf(others.get("mj_regex").toString()) * 100;
            totalMap.put("#mj_regex_t#", String.valueOf(mj_regex));
            Double icd_regex = Double.valueOf(others.get("icd_regex").toString()) * 100;
            totalMap.put("#icd_regex_t#", String.valueOf(icd_regex));
            Double highway_regex = Double.valueOf(others.get("highway_regex").toString()) * 100;
            totalMap.put("#highway_regex_t#", String.valueOf(highway_regex));
            Double fs_regex = Double.valueOf(others.get("fs_regex").toString()) * 100;
            totalMap.put("#fs_regex_t#", String.valueOf(fs_regex));
            Double ra_regex = Double.valueOf(others.get("ra_regex").toString()) * 100;
            totalMap.put("#ra_regex_t#", String.valueOf(ra_regex));

            String date_out = landProject.get("date_out").toString();
            Date parse = sdf1.parse(date_out);
            String format3 = sdf.format(parse);
            totalMap.put("#date_out#", format3);
//        String parse = sdf.format(value_date);
            String dateToCN = ParseDateToChinese.getUpperDate(date_out);
            totalMap.put("#value_date_max#", dateToCN);
            String value_date = landProject.get("value_date").toString();
            Date parse1 = sdf1.parse(value_date);
            String format4 = sdf.format(parse1);
            totalMap.put("#value_date#", format4);

            totalMap.put("#securities_getdate#", sdf.format(land_material.get("securities_getdate")));
            Date parse2 = sdf1.parse(land_material.get("out_year").toString());
            String format5 = sdf.format(parse2);
            totalMap.put("#out_year#", format5);


            if (flog) {
                //查找需要替换的字符串
                TextSelection[] textSelection = document.findAllString("#img1#", true, false);
                TextSelection[] textSelection2 = document.findAllString("#img2#", true, false);
                int index;

                //加载图片替换文本字符串
                for (Object obj : textSelection) {
                    TextSelection Selection = (TextSelection) obj;
                    DocPicture pic = new DocPicture(document);
//                    pic.loadImage("D:\\projectsd\\java\\src\\main\\resources\\img.png");
                    pic.loadImage("/home/tdbg/files/" + land_material.get("bdcdyh") + "/etc.png");
                    pic.setHeight(200);
                    pic.setWidth(350);
                    TextRange range = Selection.getAsOneRange();
                    index = range.getOwnerParagraph().getChildObjects().indexOf(range);
                    range.getOwnerParagraph().getChildObjects().insert(index, pic);
                    range.getOwnerParagraph().getChildObjects().remove(range);
                }
                //加载图片替换文本字符串
                for (Object obj : textSelection2) {
                    TextSelection Selection = (TextSelection) obj;
                    DocPicture pic = new DocPicture(document);
//                    pic.loadImage("D:\\projectsd\\java\\src\\main\\resources\\img.png");
                    pic.loadImage("/home/tdbg/proj/" + landProject.get("projectid") + "/etc.png");
                    pic.setHeight(200);
                    pic.setWidth(350);
                    TextRange range = Selection.getAsOneRange();
                    index = range.getOwnerParagraph().getChildObjects().indexOf(range);
                    range.getOwnerParagraph().getChildObjects().insert(index, pic);
                    range.getOwnerParagraph().getChildObjects().remove(range);
                }
            }


            String year = landProject.get("value_date").toString().split("-")[0];//交易时间
            String month = landProject.get("value_date").toString().split("-")[1];

            //根据年份和季度去库中找数据
       /* String quarter1PIndex = tableDao.industry_priceindex(Integer.parseInt(year), 1);
        String yearn1 = "";
        String price_index_last = quarter1PIndex;
        if (quarter1PIndex == null) {
            quarter1PIndex = "--";
            totalMap.put("#yearn#", year);
            totalMap.put("#quarter#", "1");
            //等于上个季度
            totalMap.put("#quarter1#", "1");
            yearn1 = year;
            price_index_last = quarter1PIndex;
        }
        String quarter2 = tableDao.industry_priceindex(Integer.parseInt(year), 2);
        if (quarter2 == null) {
            quarter2 = "-";
            totalMap.put("#yearn#", year);
            totalMap.put("#quarter#", "2");
            //等于上个季度
            totalMap.put("#quarter1#", "1");
            yearn1 = year;
            price_index_last = quarter1PIndex;
        }
        String quarter3 = tableDao.industry_priceindex(Integer.parseInt(year), 3);
        if (quarter3 == null) {
            quarter3 = "-";
            totalMap.put("#yearn#", year);
            totalMap.put("#quarter#", "3");
            //等于上个季度
            totalMap.put("#quarter1#", "2");
            yearn1 = year;
            price_index_last = quarter2;
        }
        String quarter4 = tableDao.industry_priceindex(Integer.parseInt(year), 4);
        if (quarter4 == null) {
            quarter4 = "-";
            totalMap.put("#yearn#", year);
            totalMap.put("#quarter#", "4");
            //等于上个季度
            totalMap.put("#quarter1#", "3");
            yearn1 = year;
            price_index_last = quarter3;
        }
        //等于上个季度
        if (quarter1PIndex == null) {
            totalMap.put("#yearn1#", yearn1);
            totalMap.put("#price_index_last#", price_index_last);
        } else {
            totalMap.put("#yearn1#", "--");
            totalMap.put("#price_index_last#", "--");
            totalMap.put("#yearn#", "--");
            totalMap.put("#quarter#", "--");
            totalMap.put("#quarter1#", "--");
        }*/

            if (flog) {
                //获取素材信息
                Map<String, Object> aCase = tableDao.land_case((int) tid.getItemDetails().get("aid"));
                Date parse3 = sdf1.parse(aCase.get("jy_date").toString());
                String format6 = sdf.format(parse3);
                aCase.put("jy_date", format6);
                toMap(totalMap, aCase, "1");
                Map<String, Object> bCase = tableDao.land_case((int) tid.getItemDetails().get("bid"));
                Date parse4 = sdf1.parse(bCase.get("jy_date").toString());
                String format7 = sdf.format(parse4);
                bCase.put("jy_date", format7);
                toMap(totalMap, bCase, "2");
                Map<String, Object> cCase = tableDao.land_case((int) tid.getItemDetails().get("cid"));
                Date parse5 = sdf1.parse(cCase.get("jy_date").toString());
                String format8 = sdf.format(parse5);
                cCase.put("jy_date", format8);
                toMap(totalMap, cCase, "3");

                double totalRegexA = Double.valueOf(resultClass.get("totalRegexA").toString());
                double totalRegexB = Double.valueOf(resultClass.get("totalRegexB").toString());
                double totalRegexC = Double.valueOf(resultClass.get("totalRegexC").toString());
                double mLastYears = Double.valueOf(resultClass.get("mLastYears").toString());
                double aLastYears = Double.valueOf(resultClass.get("aLastYears").toString());
                double bLastYears = Double.valueOf(resultClass.get("bLastYears").toString());
                double cLastYears = Double.valueOf(resultClass.get("cLastYears").toString());

                totalMap.put("#totalRegexA#", df5.format(totalRegexA));
                totalMap.put("#totalRegexB#", df5.format(totalRegexB));
                totalMap.put("#totalRegexC#", df5.format(totalRegexC));
                totalMap.put("#mLastYears#", df5.format(mLastYears));
                totalMap.put("#aLastYears#", df5.format(aLastYears));
                totalMap.put("#bLastYears#", df5.format(bLastYears));
                totalMap.put("#cLastYears#", df5.format(cLastYears));

                double a = Double.parseDouble(df.format(Double.valueOf(aCase.get("land_money").toString()) * Double.valueOf(resultClass.get("totalRegexA").toString())));
                totalMap.put("#jgA#", String.valueOf(a));
                double b = Double.parseDouble(df.format(Double.valueOf(bCase.get("land_money").toString()) * Double.valueOf(resultClass.get("totalRegexB").toString())));
                totalMap.put("#jgB#", String.valueOf(b));
                double c = Double.valueOf(df.format(Double.valueOf(cCase.get("land_money").toString()) * Double.valueOf(resultClass.get("totalRegexC").toString())));
                totalMap.put("#jgC#", String.valueOf(c));


                Double bjPrice2 = (a + b + c) / 3;
                totalMap.put("#bjPrice2#", df4.format(bjPrice2));
                totalMap.put("#bjPrice_q#", df2.format(bjPrice2));

                String region = land_material.get("regin").toString();
                String usages = land_material.get("usages").toString();
                String use_level1 = land_material.get("use_level").toString();
                totalMap.put("#use_level#", turnToRome(use_level1));


                try {
                    Map<String, Object> coblp = tableDao.getCoblp(region, usages, use_level1);
                    String unit_price = coblp.get("unit_price").toString();
                    totalMap.put("#unit_price#", unit_price);
                } catch (Exception e) {
                    e.printStackTrace();
                    return "素材表’用途‘字段有误";
                }

                //表14是通过素材表（land_material表）选择的素材的区域和等级来判断展示（wz_ccoblp||xc_ccoblp||gs_ccoblp）这三张表哪张表的数据，三张表字段现在用到的数据字段是一样的
//                String use_level = land_material.get("use_level").toString();
                String regin = land_material.get("regin").toString();
//                List<Map<String, Object>> datas = new ArrayList<Map<String, Object>>();
//                switch (regin) {
//                    case "吴中区"://表14就展示wz_ccoblp
//                        datas = tableDao.wz_ccoblp(Integer.parseInt(use_level));
//                        break;
//                    case "相城区"://表14就展示xc_ccoblp
//                        datas = tableDao.xc_ccoblp(Integer.parseInt(use_level));
//                        break;
//                    case "姑苏区"://表14就展示gs_ccoblp
//                        datas = tableDao.gs_ccoblp(Integer.parseInt(use_level));
//                        break;
//                    default:
//                        datas = tableDao.gs_ccoblp(Integer.parseInt(use_level));
//                        break;
//                }
//                toMap(totalMap, datas.get(0), "");
//                toMap(totalMap, datas.get(1), "1");
//                toMap(totalMap, datas.get(2), "2");
//                toMap(totalMap, datas.get(3), "3");
//                toMap(totalMap, datas.get(4), "4");

                Double tb16_sum = Double.valueOf(land_material.get("ra_rate").toString()) +
                        Double.valueOf(land_material.get("highway_rate").toString()) +
                        Double.valueOf(land_material.get("fs_rate").toString()) +
                        Double.valueOf(land_material.get("icd_rate").toString()) +
                        Double.valueOf(land_material.get("rr_rate").toString()) +
                        Double.valueOf(land_material.get("rl_rate").toString()) +
                        Double.valueOf(land_material.get("sr_type").toString()) +
                        Double.valueOf(land_material.get("sr_condi").toString()) +
                        Double.valueOf(land_material.get("land_shape").toString()) +
                        Double.valueOf(land_material.get("land_mj").toString()) +
                        Double.valueOf(land_material.get("al_type").toString()) +
                        Double.valueOf(land_material.get("terrain_condi").toString());
            /*Double.valueOf(totalMap.get("plan_limit").toString());
            Double.valueOf(totalMap.get("infra_rate").toString());
            Double.valueOf(totalMap.get("nature_rate").toString());*/

                //     表 16
                totalMap.put("#tb16_sum#", df4.format(tb16_sum));

                //表14
                Map<String, Object> rr_price = tableDao.rr_price(land_material.get("regin").toString(),valueDate);
                toMap(totalMap, rr_price, "");
                //判断是否五通
                String infra_des = land_material.get("infra_des").toString();
                String wtDes = "五通，即“通路、通电、通讯、供水、排水”";
                String ltDes = "六通，即“通路、通电、通讯、通燃气、供水、排水”";
                String qtDes = "七通，即“通路、通电、通讯、通燃气、供水、排雨水、排污水”";

                Integer tab14_sumA = 0;
                if (infra_des.contains("五通")) {
                    tab14_sumA = Integer.parseInt(rr_price.get("r_price").toString()) +
                            Integer.parseInt(rr_price.get("e_price").toString()) +
                            Integer.parseInt(rr_price.get("w_price").toString()) +
                            Integer.parseInt(rr_price.get("s_price").toString()) +
                            Integer.parseInt(rr_price.get("c_price").toString())+
                    //                        Integer.parseInt(rr_price.get("g_price").toString()) +
                            Integer.parseInt(rr_price.get("l_price").toString());
                    totalMap.put("#tab14_sumA#", df2.format(tab14_sumA));
                    totalMap.put("#sr_price#", "--");
                    totalMap.put("#ss_price#", "--");
                    totalMap.put("#g_price#", "--");
                    totalMap.put("#tlms#", wtDes);
                    //            totalMap.put("排污水状况：排入市政污水管网；", "排污水状况:——");
                    //            totalMap.put("排雨水状况：排入市政污水管网；", "排雨水状况:——");
                    //            totalMap.remove("region");
                    //            totalMap.put("通燃气条件：位于#region#电信局市话服务范围内；", "通燃气条件：——");
                    //            totalMap.put("#region#", regin);
                } else if (infra_des.contains("六通")) {
                    tab14_sumA = Integer.parseInt(rr_price.get("r_price").toString()) +
                            Integer.parseInt(rr_price.get("e_price").toString()) +
                            Integer.parseInt(rr_price.get("w_price").toString()) +
                            Integer.parseInt(rr_price.get("s_price").toString()) +
                            Integer.parseInt(rr_price.get("c_price").toString()) +
                            Integer.parseInt(rr_price.get("g_price").toString()) +
                            Integer.parseInt(rr_price.get("l_price").toString());
                    totalMap.put("#tab14_sumA#", df2.format(tab14_sumA));
                    totalMap.put("#sr_price#", "--");
                    totalMap.put("#ss_price#", "--");
                    totalMap.put("#tlms#", ltDes);
                    totalMap.put("排污水状况: --", "排污水状况: 排入市政污水管网；");
                    totalMap.put("排雨水状况: --", "排雨水状况: 排入市政污水管网；");
                    totalMap.put("通燃气条件: --", "通燃气条件：位于" + regin + "电信局市话服务范围内；");
                } else if (infra_des.contains("七通")) {
                    tab14_sumA = Integer.parseInt(rr_price.get("r_price").toString()) +
                            Integer.parseInt(rr_price.get("e_price").toString()) +
                            Integer.parseInt(rr_price.get("w_price").toString()) +
                            Integer.parseInt(rr_price.get("s_price").toString()) +
                            Integer.parseInt(rr_price.get("c_price").toString()) +
                            Integer.parseInt(rr_price.get("sr_price").toString()) +
                            Integer.parseInt(rr_price.get("ss_price").toString()) +
                            Integer.parseInt(rr_price.get("g_price").toString()) +
                            Integer.parseInt(rr_price.get("l_price").toString());
                    totalMap.put("#tab14_sumA#", df2.format(tab14_sumA));
                    totalMap.put("排污水状况: --", "排污水状况: 排入市政污水管网；");
                    totalMap.put("排雨水状况: --", "排雨水状况: 排入市政污水管网；");
                    totalMap.put("通燃气条件: --", "通燃气条件：位于" + regin + "电信局市话服务范围内；");
                    totalMap.put("#tlms#", qtDes);
                } else {
                    tab14_sumA = Integer.parseInt(rr_price.get("r_price").toString()) +
                            Integer.parseInt(rr_price.get("e_price").toString()) +
                            Integer.parseInt(rr_price.get("w_price").toString()) +
                            Integer.parseInt(rr_price.get("s_price").toString()) +
                            Integer.parseInt(rr_price.get("c_price").toString()) +
                    //                        Integer.parseInt(rr_price.get("g_price").toString()) +
                            Integer.parseInt(rr_price.get("l_price").toString());
                    totalMap.put("#tab14_sumA#", df2.format(tab14_sumA));
                    totalMap.put("#sr_price#", "--");
                    totalMap.put("#ss_price#", "--");
                    totalMap.put("#g_price#", "--");
                    totalMap.put("#tlms#", wtDes);
                }
                String plot_ratio = land_material.get("plot_ratio").toString();
                if (Double.valueOf(plot_ratio) > 0.8) {
                    String aa = "容积率符合《工业项目建设用地控制指标》的要求。估价人员认为在现状用途和利用条件下，待估宗地达到最佳利用从而获得最大收益";
                    totalMap.put("#DES_ratio#", aa);
                } else {
                    String aa = "根据苏州市人民政府《关于贯彻国务院深化改革严格土地管理的决定的实施意见》的规定，工业项目规划指标必须符合国土资源部颁" +
                            "发的《工业项目建设用地控制指标》标准，总体上建筑系数应大于0.5、容积率大于0.8。待估宗地目前建筑容积率为" + plot_ratio + "，未达到该文件规定的下限，该宗地未达到最有效利用";
                    totalMap.put("#DES_ratio#", aa);
                }


                String aInfraDes = aCase.get("infra_des").toString();
                String bInfraDes = bCase.get("infra_des").toString();
                String cInfraDes = cCase.get("infra_des").toString();
                if (aInfraDes.contains("五通"))
                    totalMap.put("#Atlms#", wtDes);
                else if (aInfraDes.contains("六通"))
                    totalMap.put("#Atlms#", ltDes);
                else
                    totalMap.put("#Atlms#", qtDes);

                if (bInfraDes.contains("五通"))
                    totalMap.put("#Btlms#", wtDes);
                else if (bInfraDes.contains("六通"))
                    totalMap.put("#Btlms#", ltDes);
                else
                    totalMap.put("#Btlms#", qtDes);

                if (cInfraDes.contains("五通"))
                    totalMap.put("#Ctlms#", wtDes);
                else if (cInfraDes.contains("六通"))
                    totalMap.put("#Ctlms#", ltDes);
                else
                    totalMap.put("#Ctlms#", qtDes);

                // 1.计算1 land_outyearn = 素材表land_outyear减去value_date
                DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
                String land_outyearn = null;
                try {
                    String caseYear = yearCompare(format1.parse(land_material.get("out_year").toString()), format1.parse(landProject.get("value_date").toString()));
                    land_outyearn = new BigDecimal(Double.valueOf(caseYear)).setScale(2, RoundingMode.DOWN).toString();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                totalMap.put("#land_outyearn#", land_outyearn);
                double ysy_date = 50 - Double.valueOf(land_outyearn);
                totalMap.put("#ysy_date#", df4.format(ysy_date));

                //表13
                String region_level = tid.getItemDetails().get("qpdj").toString();

                List<Map<String, Object>> cbbj_database1 = tableDao.cbbj_database(regin, region_level, valueDate);
                Map<String, Object> cbbj_database = cbbj_database1.get(0);
                toMap(totalMap, cbbj_database, "");

                double gdzb = Double.valueOf(tid.getItemDetails().get("gdzb").toString()) * 100;
                double ydzb = Double.valueOf(tid.getItemDetails().get("ydzb").toString()) * 100;
                double qtnyzb = Double.valueOf(tid.getItemDetails().get("qtnyzb").toString()) * 100;
                double jzzbzb = Double.valueOf(tid.getItemDetails().get("jzzbzb").toString()) * 100;
                double wlyzb = Double.valueOf(tid.getItemDetails().get("wlyzb").toString()) * 100;


                //返回2位小数，并且四舍五入

                totalMap.put("#gdzb#", df.format(gdzb));
                totalMap.put("#ydzb#", df.format(ydzb));
                totalMap.put("#qtnyzb#", df.format(qtnyzb));
                totalMap.put("#jzzbzb#", df.format(jzzbzb));
                totalMap.put("#wlyzb#", df.format(wlyzb));

                double gdydqt_sum = gdzb + ydzb + qtnyzb;
                totalMap.put("#gdydqt_sum#", df.format(gdydqt_sum));


                //        String land_mj = land_material.get("land_mj").toString();
                //        String format = df2.format(land_mj);
                //        totalMap.remove("land_mj");
                //        totalMap.put("land_mj", format);

                //土地补偿
                String tdbc_price = cbbj_database.get("tdbc_price").toString();
                //        String land_mj = land_material.get("land_mj").toString();
                totalMap.put("#tdbc_price#", tdbc_price);
                //未利用地
                double wlyd = Double.valueOf(tdbc_price) * 0.7;
                totalMap.put("#wlyd#", String.valueOf(wlyd));
                totalMap.put("#qmbc_price#", cbbj_database.get("qmbc_price").toString());
                totalMap.put("#kfjs_price#", cbbj_database.get("kfjs_price").toString());
                totalMap.put("#gdkk_price#", cbbj_database.get("gdkk_price").toString());
                totalMap.put("#gdzy_price#", cbbj_database.get("gdzy_price").toString());

                //土地平均标准
                double tab13_count1 = (gdzb * Double.valueOf(tdbc_price) +
                        ydzb * Double.valueOf(tdbc_price) +
                        qtnyzb * Double.valueOf(tdbc_price) +
                        jzzbzb * Double.valueOf(tdbc_price) +
                        wlyzb * wlyd) / 100;
                totalMap.put("#tab13_count1#", df2.format(tab13_count1));
                String rjnyd = cbbj_database.get("rjnyd").toString();
                String azbc_price = cbbj_database.get("azbc_price").toString();
                double tab13_count2 = (gdydqt_sum / Double.valueOf(rjnyd) * Double.valueOf(azbc_price)) / 100;
                //        totalMap.put("#tab13_count2#", df2.format(tab13_count2));
                double tab13_count3 = (Double.valueOf(cbbj_database.get("qmbc_price").toString()) * gdzb +
                        Double.valueOf(cbbj_database.get("qmbc_price").toString()) * ydzb +
                        Double.valueOf(cbbj_database.get("qmbc_price").toString()) * qtnyzb) / 100;
                double tab13_count4 = Double.valueOf(tid.getItemDetails().get("dsfzw").toString());//todo

                double tab13_count5 = (Double.valueOf(cbbj_database.get("kfjs_price").toString()) * gdzb +
                        Double.valueOf(cbbj_database.get("kfjs_price").toString()) * ydzb +
                        Double.valueOf(cbbj_database.get("kfjs_price").toString()) * qtnyzb) / 100;
                double tab13_count6 = (Double.valueOf(cbbj_database.get("gdkk_price").toString()) * gdzb +
                        Double.valueOf(cbbj_database.get("gdkk_price").toString()) * ydzb +
                        Double.valueOf(cbbj_database.get("gdkk_price").toString()) * qtnyzb) / 100;
                double tab13_count7 = (Double.valueOf(cbbj_database.get("gdzy_price").toString()) * gdzb +
                        Double.valueOf(cbbj_database.get("gdzy_price").toString()) * ydzb +
                        Double.valueOf(cbbj_database.get("gdzy_price").toString()) * qtnyzb) / 100;
                totalMap.put("#tab13_count2#", df2.format(tab13_count2));
                totalMap.put("#tab13_count3#", df2.format(tab13_count3));
                totalMap.put("#tab13_count4#", df2.format(tab13_count4));
                totalMap.put("#tab13_count5#", df2.format(tab13_count5));
                totalMap.put("#tab13_count6#", df2.format(tab13_count6));
                totalMap.put("#tab13_count7#", df2.format(tab13_count7));
                double tab13_sum = tab13_count1 + tab13_count2 + tab13_count3 + tab13_count4
                        + tab13_count5 + tab13_count6 + tab13_count7;
                totalMap.put("#tab13_sum#", df2.format(tab13_sum));

                //表8
                //月份所在的季度
                Integer jd = null;
                switch (month) {
                    case "01":
                    case "02":
                    case "03":
                        jd = 1;
                        break;
                    case "04":
                    case "05":
                    case "06":
                        jd = 2;
                        break;
                    case "07":
                    case "08":
                    case "09":
                        jd = 3;
                        break;
                    default:
                        jd = 4;
                        break;
                }

                String year03 = year;
                totalMap.put("#year#", year);
                String year02 = String.valueOf(Integer.parseInt(year) - 1);
                String year01 = String.valueOf(Integer.parseInt(year) - 2);
                String year00 = String.valueOf(Integer.parseInt(year) - 3);
                //        totalMap.put("#year3#", year03);
                //        totalMap.put("#year2#", year02);
                //        totalMap.put("#year1#", year01);
                String quarter01 = null;
                String quarter02 = null;
                String quarter03 = null;
                String quarter04 = null;
                String quarter01_year02 = null;
                String quarter02_year02 = null;
                String quarter03_year02 = null;
                String quarter04_year02 = null;
                String quarter01_year03 = null;
                String quarter02_year03 = null;
                String quarter03_year03 = null;
                String quarter04_year03 = null;

                if (jd == 1) {
                    quarter01 = tableDao.industry_priceindex(Integer.parseInt(year), 1);
                    quarter02 = tableDao.industry_priceindex(Integer.parseInt(year02), 4);
                    quarter03 = tableDao.industry_priceindex(Integer.parseInt(year02), 3);
                    quarter04 = tableDao.industry_priceindex(Integer.parseInt(year02), 2);
                    quarter01_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 1);
                    quarter02_year02 = tableDao.industry_priceindex(Integer.parseInt(year01), 4);
                    quarter03_year02 = tableDao.industry_priceindex(Integer.parseInt(year01), 3);
                    quarter04_year02 = tableDao.industry_priceindex(Integer.parseInt(year01), 2);
                    quarter01_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 1);
                    quarter02_year03 = tableDao.industry_priceindex(Integer.parseInt(year00), 4);
                    quarter03_year03 = tableDao.industry_priceindex(Integer.parseInt(year00), 3);
                    quarter04_year03 = tableDao.industry_priceindex(Integer.parseInt(year00), 2);
                    totalMap.put("#year" + 12 + "#", year);
                    totalMap.put("#year" + 11 + "#", year02);
                    totalMap.put("#year" + 10 + "#", year02);
                    totalMap.put("#year" + 9 + "#", year02);
                    totalMap.put("#year" + 8 + "#", year02);
                    totalMap.put("#year" + 7 + "#", year01);
                    totalMap.put("#year" + 6 + "#", year01);
                    totalMap.put("#year" + 5 + "#", year01);
                    totalMap.put("#year" + 4 + "#", year01);
                    totalMap.put("#year" + 3 + "#", year00);
                    totalMap.put("#year" + 2 + "#", year00);
                    totalMap.put("#year" + 1 + "#", year00);

                    totalMap.put("#jd" + 12 + "#", "1");
                    totalMap.put("#jd" + 11 + "#", "4");
                    totalMap.put("#jd" + 10 + "#", "3");
                    totalMap.put("#jd" + 9 + "#", "2");
                    totalMap.put("#jd" + 8 + "#", "1");
                    totalMap.put("#jd" + 7 + "#", "4");
                    totalMap.put("#jd" + 6 + "#", "3");
                    totalMap.put("#jd" + 5 + "#", "2");
                    totalMap.put("#jd" + 4 + "#", "1");
                    totalMap.put("#jd" + 3 + "#", "4");
                    totalMap.put("#jd" + 2 + "#", "3");
                    totalMap.put("#jd" + 1 + "#", "2");
                } else if (jd == 2) {
                    quarter01 = tableDao.industry_priceindex(Integer.parseInt(year), 2);
                    quarter02 = tableDao.industry_priceindex(Integer.parseInt(year), 1);
                    quarter03 = tableDao.industry_priceindex(Integer.parseInt(year02), 4);
                    quarter04 = tableDao.industry_priceindex(Integer.parseInt(year02), 3);
                    quarter01_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 2);
                    quarter02_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 1);
                    quarter03_year02 = tableDao.industry_priceindex(Integer.parseInt(year01), 4);
                    quarter04_year02 = tableDao.industry_priceindex(Integer.parseInt(year01), 3);
                    quarter01_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 2);
                    quarter02_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 1);
                    quarter03_year03 = tableDao.industry_priceindex(Integer.parseInt(year00), 4);
                    quarter04_year03 = tableDao.industry_priceindex(Integer.parseInt(year00), 3);
                    totalMap.put("#year" + 12 + "#", year);
                    totalMap.put("#year" + 11 + "#", year);
                    totalMap.put("#year" + 10 + "#", year02);
                    totalMap.put("#year" + 9 + "#", year02);
                    totalMap.put("#year" + 8 + "#", year02);
                    totalMap.put("#year" + 7 + "#", year02);
                    totalMap.put("#year" + 6 + "#", year01);
                    totalMap.put("#year" + 5 + "#", year01);
                    totalMap.put("#year" + 4 + "#", year01);
                    totalMap.put("#year" + 3 + "#", year01);
                    totalMap.put("#year" + 2 + "#", year00);
                    totalMap.put("#year" + 1 + "#", year00);

                    totalMap.put("#jd" + 12 + "#", "2");
                    totalMap.put("#jd" + 11 + "#", "1");
                    totalMap.put("#jd" + 10 + "#", "4");
                    totalMap.put("#jd" + 9 + "#", "3");
                    totalMap.put("#jd" + 8 + "#", "2");
                    totalMap.put("#jd" + 7 + "#", "1");
                    totalMap.put("#jd" + 6 + "#", "4");
                    totalMap.put("#jd" + 5 + "#", "3");
                    totalMap.put("#jd" + 4 + "#", "2");
                    totalMap.put("#jd" + 3 + "#", "1");
                    totalMap.put("#jd" + 2 + "#", "4");
                    totalMap.put("#jd" + 1 + "#", "3");
                } else if (jd == 3) {
                    quarter01 = tableDao.industry_priceindex(Integer.parseInt(year), 3);
                    quarter02 = tableDao.industry_priceindex(Integer.parseInt(year), 2);
                    quarter03 = tableDao.industry_priceindex(Integer.parseInt(year), 1);
                    quarter04 = tableDao.industry_priceindex(Integer.parseInt(year02), 4);
                    quarter01_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 3);
                    quarter02_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 2);
                    quarter03_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 1);
                    quarter04_year02 = tableDao.industry_priceindex(Integer.parseInt(year01), 4);
                    quarter01_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 3);
                    quarter02_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 2);
                    quarter03_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 1);
                    quarter04_year03 = tableDao.industry_priceindex(Integer.parseInt(year00), 4);
                    totalMap.put("#year" + 12 + "#", year);
                    totalMap.put("#year" + 11 + "#", year);
                    totalMap.put("#year" + 10 + "#", year);
                    totalMap.put("#year" + 9 + "#", year02);
                    totalMap.put("#year" + 8 + "#", year02);
                    totalMap.put("#year" + 7 + "#", year02);
                    totalMap.put("#year" + 6 + "#", year02);
                    totalMap.put("#year" + 5 + "#", year01);
                    totalMap.put("#year" + 4 + "#", year01);
                    totalMap.put("#year" + 3 + "#", year01);
                    totalMap.put("#year" + 2 + "#", year01);
                    totalMap.put("#year" + 1 + "#", year00);

                    totalMap.put("#jd" + 12 + "#", "3");
                    totalMap.put("#jd" + 11 + "#", "2");
                    totalMap.put("#jd" + 10 + "#", "1");
                    totalMap.put("#jd" + 9 + "#", "4");
                    totalMap.put("#jd" + 8 + "#", "3");
                    totalMap.put("#jd" + 7 + "#", "2");
                    totalMap.put("#jd" + 6 + "#", "1");
                    totalMap.put("#jd" + 5 + "#", "4");
                    totalMap.put("#jd" + 4 + "#", "3");
                    totalMap.put("#jd" + 3 + "#", "2");
                    totalMap.put("#jd" + 2 + "#", "1");
                    totalMap.put("#jd" + 1 + "#", "4");
                } else {
                    quarter01 = tableDao.industry_priceindex(Integer.parseInt(year), 4);
                    quarter02 = tableDao.industry_priceindex(Integer.parseInt(year), 3);
                    quarter03 = tableDao.industry_priceindex(Integer.parseInt(year), 2);
                    quarter04 = tableDao.industry_priceindex(Integer.parseInt(year), 1);
                    quarter01_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 4);
                    quarter02_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 3);
                    quarter03_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 2);
                    quarter04_year02 = tableDao.industry_priceindex(Integer.parseInt(year02), 1);
                    quarter01_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 4);
                    quarter02_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 3);
                    quarter03_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 2);
                    quarter04_year03 = tableDao.industry_priceindex(Integer.parseInt(year01), 1);
                    totalMap.put("#year" + 12 + "#", year);
                    totalMap.put("#year" + 11 + "#", year);
                    totalMap.put("#year" + 10 + "#", year);
                    totalMap.put("#year" + 9 + "#", year);
                    totalMap.put("#year" + 8 + "#", year02);
                    totalMap.put("#year" + 7 + "#", year02);
                    totalMap.put("#year" + 6 + "#", year02);
                    totalMap.put("#year" + 5 + "#", year02);
                    totalMap.put("#year" + 4 + "#", year01);
                    totalMap.put("#year" + 3 + "#", year01);
                    totalMap.put("#year" + 2 + "#", year01);
                    totalMap.put("#year" + 1 + "#", year01);

                    totalMap.put("#jd" + 12 + "#", "4");
                    totalMap.put("#jd" + 11 + "#", "3");
                    totalMap.put("#jd" + 10 + "#", "2");
                    totalMap.put("#jd" + 9 + "#", "1");
                    totalMap.put("#jd" + 8 + "#", "4");
                    totalMap.put("#jd" + 7 + "#", "3");
                    totalMap.put("#jd" + 6 + "#", "2");
                    totalMap.put("#jd" + 5 + "#", "1");
                    totalMap.put("#jd" + 4 + "#", "4");
                    totalMap.put("#jd" + 3 + "#", "3");
                    totalMap.put("#jd" + 2 + "#", "2");
                    totalMap.put("#jd" + 1 + "#", "1");
                }


                if (quarter01 == null) {
                    totalMap.put("#price_index" + 12 + "#", "--");
                    totalMap.put("#yearn#", year);
                    totalMap.put("#yearn1#", year);
                    totalMap.put("#quarter#", String.valueOf(jd));
                    totalMap.put("#quarter1#", String.valueOf(jd == 1 ? 4 : jd - 1));
                } else {
                    totalMap.put("#price_index" + 12 + "#", quarter01);
                    totalMap.put("因#yearn#年#quarter#季度地价指数未公布，考虑到工业用地地价平稳，近期无重大波动，因此，本次估价过程中#yearn#年#quarter#季度指数以日期上最接近的#yearn1#年#quarter1#季度的地价指数为准。则待估宗地与各实例的地价指数如下表9:", "则待估宗地与各实例的地价指数如下表9:");
                }
                if (quarter02 == null) {
                    totalMap.put("#price_index" + 11 + "#", "--");
                    totalMap.put("#yearn#", year);
                    totalMap.put("#yearn1#", year);
                    totalMap.put("#quarter#", String.valueOf(jd));
                    totalMap.put("#quarter1#", String.valueOf(jd == 1 ? 4 : jd - 1));
                } else {
                    totalMap.put("#price_index" + 11 + "#", quarter02);
                }
                if (quarter03 == null) {
                    totalMap.put("#price_index" + 10 + "#", "--");
                    totalMap.put("#yearn#", year);
                    totalMap.put("#yearn1#", year);
                    totalMap.put("#quarter#", String.valueOf(jd));
                    totalMap.put("#quarter1#", String.valueOf(jd == 1 ? 4 : jd - 1));
                } else {
                    totalMap.put("#price_index" + 10 + "#", quarter03);
                }
                if (quarter04 == null) {
                    totalMap.put("#price_index" + 9 + "#", "--");
                    totalMap.put("#yearn#", year);
                    totalMap.put("#yearn1#", String.valueOf(Integer.valueOf(year) - 1));
                    totalMap.put("#quarter#", String.valueOf(jd));
                    totalMap.put("#quarter1#", String.valueOf(jd == 1 ? 4 : jd - 1));
                } else {
                    totalMap.put("#price_index" + 9 + "#", quarter04);
                }
                if (quarter01_year02 == null) {
                    totalMap.put("#price_index" + 8 + "#", "--");
                } else {
                    totalMap.put("#price_index" + 8 + "#", quarter01_year02);
                }
                if (quarter02_year02 == null) {
                    totalMap.put("#price_index" + 7 + "#", "--");
                } else {
                    totalMap.put("#price_index" + 7 + "#", quarter02_year02);
                }
                if (quarter03_year02 == null) {
                    totalMap.put("#price_index" + 6 + "#", "--");
                } else {
                    totalMap.put("#price_index" + 6 + "#", quarter03_year02);
                }
                if (quarter04_year02 == null) {
                    totalMap.put("#price_index" + 5 + "#", "--");
                } else {
                    totalMap.put("#price_index" + 5 + "#", quarter04_year02);
                }
                if (quarter01_year03 == null) {
                    totalMap.put("#price_index" + 4 + "#", "--");
                } else {
                    totalMap.put("#price_index" + 4 + "#", quarter01_year03);
                }
                if (quarter02_year03 == null) {
                    totalMap.put("#price_index" + 3 + "#", "--");
                } else {
                    totalMap.put("#price_index" + 3 + "#", quarter02_year03);
                }
                if (quarter03_year03 == null) {
                    totalMap.put("#price_index" + 2 + "#", "--");
                } else {
                    totalMap.put("#price_index" + 2 + "#", quarter03_year03);
                }
                if (quarter04_year03 == null) {
                    totalMap.put("#price_index" + 1 + "#", "--");
                } else {
                    totalMap.put("#price_index" + 1 + "#", quarter04_year03);
                }


                //#price_index_next}按指导文件估价期日
                //        String region_name = land_material.get("regin").toString();//素材表区域
                //        Map<String, Object> guidance = tableDao.guidance_document(region_name).get(0);
                //        String announcementDate = guidance.get("announcement_date").toString().split("-")[1];

                //        totalMap.put("#price_index_next#", price_index_next);

                //表2总地价
//                String securities_areatotal = land_material.get("securities_areatotal").toString();//总面积
//                String land_money = land_material.get("land_money").toString();//面积单价
//                double securities_areatotal_sum = Double.valueOf(securities_areatotal) * Double.valueOf(land_money) / 10000;
//                totalMap.put("#securities_areatotal_sum#", df.format(securities_areatotal_sum));
//                double sum_money_max = Double.valueOf(df.format(securities_areatotal_sum)) * 10000;
//                String format2 = df2.format(sum_money_max);
//                //大写总金额
//                totalMap.put("#sum_money_max#", ParseMoneyUtils.dealMoney(format2));

                String gdkk_price = cbbj_database.get("gdkk_price").toString();
                double gdkk_price_z = Double.valueOf(gdkk_price) / 666.6667;
                totalMap.put("#gdkk_price_z#", df.format(gdkk_price_z));

                String gdzy_price = cbbj_database.get("gdzy_price").toString();
                double gdzy_price_z = Double.valueOf(gdzy_price) / 666.6667;
                totalMap.put("#gdzy_price_z#", df.format(gdzy_price_z));

                //表15土地取得费
                String s = totalMap.get("#tab13_sum#");
                double tdqdf = Double.valueOf(s) / 666.6667;
                totalMap.put("#tdqdf#", df.format(tdqdf));
                //土地开发费=tab14_sum
                //平整费
                String l_price = rr_price.get("l_price").toString();
                totalMap.put("#l_price#", l_price);
                //利息
                double tab14_sum = tab14_sumA - 10;
                totalMap.put("#tab14_sum#", df2.format(tab14_sum));

                double csa = (tdqdf + tab14_sum)
                        * ((1 + 0.0435) - 1);
                double csb = Double.valueOf(l_price) *
                        (Math.pow(1 + 0.0435, 0.5) - 1);
                double lx = csa + csb;

                totalMap.put("#lx#", df.format(lx));
                double tzlr = (tdqdf + tab14_sum + Double.valueOf(l_price)) * 0.065;
                totalMap.put("#tzlr#", df.format(tzlr));
                double tdzz_percent1 = Double.valueOf(cbbj_database.get("tdzz_percent").toString());
                String tdzz_percent = df2.format(tdzz_percent1 * 100);
                totalMap.put("#tdzz_percent#", tdzz_percent);
                double tdzzsy = (tdqdf + tab14_sum + Double.valueOf(l_price) + lx + tzlr) * tdzz_percent1;
                totalMap.put("#tdzzsy#", df.format(tdzzsy));
                //pow剩余使用年限
                double nqxzxs = (1 - 1 / Math.pow(1 + 0.054, Double.valueOf(land_outyearn))) / (1 - 1 / Math.pow(1 + 0.054, 50));
                totalMap.put("#nqxzxs#", df5.format(nqxzxs));
                //计算待估宗地土地价格
                Double cbjt_regex = Double.valueOf(others.get("cbjt_regex").toString());
                totalMap.put("#cbjt_regex_des#", cbjt_regex==0 ? "相当" : cbjt_regex > 0 ? "相比较较优" : "较劣");

                Double cbjcss_regex = Double.valueOf(others.get("cbjcss_regex").toString());
                totalMap.put("#cbjcss_regex_des#", cbjcss_regex==0 ? "相当" : cbjcss_regex > 0 ? "相比较较优" : "较劣");

                Double cbhjzl_regex = Double.valueOf(others.get("cbhjzl_regex").toString());
                totalMap.put("#cbhjzl_regex_des#", cbhjzl_regex==0 ? "相当" : cbhjzl_regex > 0 ? "相比较较优" : "较劣");

                Double cbghys_regex = Double.valueOf(others.get("cbghys_regex").toString());
                totalMap.put("#cbghys_regex_des#", cbghys_regex==0 ? "相当" : cbghys_regex > 0 ? "相比较较优" : "较劣");

                Double cbgbtj_regex = Double.valueOf(others.get("cbgbtj_regex").toString());
                totalMap.put("#cbgbtj_regex_des#", cbgbtj_regex==0 ? "相当" : cbgbtj_regex > 0 ? "相比较较优" : "较劣");

                Double cbcyjj_regex = Double.valueOf(others.get("cbcyjj_regex").toString());
                totalMap.put("#cbcyjj_regex_des#", cbcyjj_regex==0 ? "相当" : cbcyjj_regex > 0 ? "相比较较优" : "较劣");


                double regex_sum = cbjt_regex + cbjcss_regex + cbhjzl_regex + cbghys_regex + cbgbtj_regex + cbcyjj_regex;
                totalMap.put("#regex_sum#", df5.format(regex_sum).equals("0.00") ? "0" : df.format(regex_sum));

                double js_regex_sum = regex_sum / 100;

                double js_dgzdtdjg = (tdqdf + tab14_sum + Double.valueOf(l_price) + lx + tzlr + tdzzsy) * nqxzxs * (1 + js_regex_sum);
                totalMap.put("#js_dgzdtdjg#", df.format(js_dgzdtdjg));
                DecimalFormat df1 = new DecimalFormat("######0");
                totalMap.put("#qz_dgzdtdjg#", df1.format(js_dgzdtdjg));

                double bj_price = 0;
                totalMap.put("#bj_price#", String.valueOf(bj_price));
                //计算单位面积土地价格
                double dwmjtdjg = (Double.valueOf(resultClass.get("bjPrice").toString()) + Double.valueOf(totalMap.get("#qz_dgzdtdjg#"))) / 2;
                totalMap.put("#dwmjtdjg#", df2.format(dwmjtdjg));

                //估价结果
                //        String securities_areatotal = land_material.get("securities_areatotal").toString();//总面积
                double securities_areatotal_sum1 = Double.valueOf(land_material.get("land_mj").toString()) * Double.valueOf(df2.format(dwmjtdjg)) / 10000;
                totalMap.put("#securities_areatotal_sum1#", df.format(securities_areatotal_sum1));
                double sum_money_max1 = Double.valueOf(df.format(securities_areatotal_sum1)) * 10000;
                String format = df2.format(sum_money_max1);
                //大写总金额
                totalMap.put("#sum_money_max1#", ParseMoneyUtils.dealMoney(format));

                String src_des = totalMap.get("#src_des#");
                if (src_des.contains("四面临路")) {
                    totalMap.put("#src_des_t#", "宗地" + src_des + "，临路条件优");
                } else if (src_des.contains("三面临路")) {
                    totalMap.put("#src_des_t#", "宗地" + src_des + "，临路条件较优");
                } else if (src_des.contains("二面临路")) {
                    totalMap.put("#src_des_t#", "宗地" + src_des + "，临路条件较优");
                } else if (src_des.contains("一面临路")) {
                    totalMap.put("#src_des_t#", "宗地" + src_des + "，临路条件一般");
                } else {
                    totalMap.put("#src_des_t#", "宗地" + src_des + "，临路条件劣");
                }
                totalMap.put("#qllx#", land_material.get("qllx") == null ? "" : land_material.get("qllx").toString());

                totalMap.put("#text#", "\n\n\n\n\n\n\n              " +
                        "        第四部分    附 件\n" +
                        "\n" +
                        "       附件1 土地估价委托书复印件\n" +
                        "       附件2《不动产权证书》复印件\n" +
                        "       附件3 委托方营业执照复印件\n" +
                        "       附件4 估价机构营业执照复印件\n" +
                        "       附件5 估价机构备案函复印件\n" +
                        "       附件6 估价人员资格证书复印件\n" +
                        "       附件7 估价对象现状照片\n" +
                        "       附件8 估价对象及可比实例位置示意图\n" +
                        "       附件9《现场查勘记录表》\n" +
                        "       附件10 可比实例的照片");

                Set<Map.Entry<String, String>> entries = totalMap.entrySet();
                for (Map.Entry<String, String> entry : entries) {
                    if (entry.getKey() != null && entry.getValue() != null) {
                        int i1 = document.replace(entry.getKey(), entry.getValue(), false, true);
//                        if (i1 != 0) {
//                            System.out.println(entry.getKey() + "->替换为: " + entry.getValue());
//                        } else {
//                            System.out.println(entry.getKey() + "->未替换: " + entry.getValue());
//                        }
                    }
                }
                String projectid = landProject.get("projectid").toString();
                tableDao.setpPath(Integer.valueOf(projectid), "/home/tdbg/bjf/" + land_material.get("bdcdyh") + ".doc");//todo
                //保存文档
                document.saveToFile("/home/tdbg/bjf/" + land_material.get("bdcdyh") + ".doc", FileFormat.Doc);
//                document.saveToFile("D:\\projectsd\\java\\src\\main\\resources\\word\\newword\\temp.doc", FileFormat.Doc);
//                document.saveToFile("D:\\temp.doc", FileFormat.Doc);
            }

//        String ra_des_pj = totalMap.get("#ra_des_pj#");
//        String infra_des_pj = totalMap.get("#infra_des_pj#");
//        String icd_des_pj = totalMap.get("#icd_des_pj#");
//        String nature_des = totalMap.get("#nature_des#");
//        String landusr_type = totalMap.get("#landusr_type#");
//        String eff_des = totalMap.get("#eff_des#");
//        String area_des = totalMap.get("#area_des#");
//        String shape_des = totalMap.get("#shape_des#");
//        String src_des = totalMap.get("#src_des#");
            String ra_des_pj = totalMap.get("#ra_des#");
            String infra_des_pj = totalMap.get("#infra_des#");
            String icd_des_pj = totalMap.get("#icd_des#");
            String nature_des = totalMap.get("#nature_des#");
            String landusr_type = totalMap.get("#landusr_type#");
            String eff_des = totalMap.get("#eff_des#");
            String area_des = totalMap.get("#area_des#");
            String shape_des = totalMap.get("#shape_des#");
            String src_des = totalMap.get("#src_des#");

            hashMap = new HashMap<>();

            if (flog) {
                hashMap.put("p_path", "/home/tdbg/bjf/" + land_material.get("bdcdyh") + ".doc");
            } else {
                hashMap.put("2.6.2zsss", "待估宗地所在区域交通条件" + ra_des_pj + "，基础设施" + infra_des_pj
                        + "，产业聚集程度" + icd_des_pj + "，环境" + nature_des + "，作为" + landusr_type +
                        "与区域规划相协调，综合评价影响待估宗地的区域条件" + eff_des + "。");
                hashMap.put("3.1.2zsss", "待估宗地" + area_des + "，宗地" + shape_des + "，临路条件" + src_des +
                        "，地形地势地质一般，宗地内基础设施已形成，无特殊规划限制，综合评价影响估价对象地价的个别因素条件" + eff_des + "。");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }

        return hashMap;
    }

    Map<String, String> toMap(Map<String, String> totalMap, Map<String, Object> map, String IndexNo) {
        if (map != null && map.size() > 0) {
            for (String key : map.keySet()) {
                if (map.get(key) != null) {
                    if (IndexNo.length() > 0) {
                        String keytemp = key.concat(IndexNo);
                        totalMap.put("#".concat(keytemp).concat("#"), map.get(key).toString());
                    } else {
                        totalMap.put("#".concat(key).concat("#"), map.get(key).toString());
                    }
                } else {
                    if (IndexNo.length() > 0) {
                        String keytemp = key.concat(IndexNo);
                        totalMap.put("#".concat(keytemp).concat("#"), "");
                    } else {
                        totalMap.put("#".concat(key).concat("#"), "");
                    }
                }
            }
        }
        return totalMap;
    }

    /**
     * 计算2个日期相差多少年
     * <p>
     * 列：2011-02-02  ~  2017-03-02 大约相差 6.1 年
     *
     * @param fromDate
     * @param toDate
     * @return
     */
    public static String yearCompare(Date fromDate, Date toDate) {
        DayCompare result = dayComparePrecise(fromDate, toDate);
        double month = result.getMonth();
        double year = result.getYear();
        double day = result.getDay();
        //返回2位小数，并且四舍五入
        DecimalFormat df = new DecimalFormat("######0.000");
        return df.format(Math.abs(year + month / 12 + day / 365.25));
    }

    /**
     * 计算2个日期之间相差的  相差多少年月日
     * 比如：2011-02-02 到  2017-03-02 相差 6年，1个月，0天
     *
     * @param fromDate
     * @param toDate
     * @return
     */
    public static DayCompare dayComparePrecise(Date fromDate, Date toDate) {
        Calendar from = Calendar.getInstance();
        from.setTime(fromDate);
        Calendar to = Calendar.getInstance();
        to.setTime(toDate);

        int fromYear = from.get(Calendar.YEAR);
        int fromMonth = from.get(Calendar.MONTH);
        int fromDay = from.get(Calendar.DAY_OF_MONTH);

        int toYear = to.get(Calendar.YEAR);
        int toMonth = to.get(Calendar.MONTH);
        int toDay = to.get(Calendar.DAY_OF_MONTH);
        int year = toYear - fromYear;
        int month = toMonth - fromMonth;
        int day = toDay - fromDay;
        DayCompare dayCompare = new DayCompare();
        dayCompare.setYear(year);
        dayCompare.setMonth(month);
        dayCompare.setDay(day);
        return dayCompare;
    }

    public static String turnToRome(String str){
        String[] arr = new String[]{"","Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ","Ⅸ"};
//        StringBuilder sb = new StringBuilder(str);
        StringBuilder sb = new StringBuilder();
        int num = 0;
        for (int i = 0; i < str.length(); i++) {
//            System.out.println(str.charAt(i));
            num = str.charAt(i) - '0';
            sb.append(arr[num]);
        }
        return sb.toString();
    }
}
